package com.xiaotu.spider.aiman.pipeline;

import org.springframework.stereotype.Component;

import com.xiaotu.common.model.StarFansDetail;
import com.xiaotu.common.model.StarFansPeople;
import com.xiaotu.common.util.Constants;
import com.xiaotu.common.util.DataRedisKeyUtils;
import com.xiaotu.spider.APipeline;

import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;

/**
 * @类名 StarAiManPipeline
 * @日期 2017年11月29日
 * @作者 王艳龙
 * @功能 艾漫明星粉丝pipeline
 */

@Component("StarAiManPipeline")
public class StarAiManPipeline extends APipeline
{
    @Override
    protected void doProcess(ResultItems resultItems, Task task)
    {
    	StarFansDetail detail = resultItems.get(StarFansDetail.class.getName());
        if (detail == null)
            return;
        String key = DataRedisKeyUtils.getKey(Constants.DataRedisKey.STAR_AIMAN_DETAIL_YYYYMMDD);
    	cacheHandler.hSet(key, detail.getStarId(), detail);
        cacheHandler.setCacheTimeout(key);
        
        StarFansPeople people = resultItems.get(StarFansPeople.class.getName());
        if (people == null)
            return;
        String key_art = DataRedisKeyUtils.getKey(Constants.DataRedisKey.STAR_AIMAN_PEOPLE_YYYYMMDD);
    	cacheHandler.hSet(key_art, people.getStarId(), people);
        cacheHandler.setCacheTimeout(key_art);
    }

}
